package com.guoxin.part4.chapter15;

import java.util.concurrent.TimeUnit;

/**
 * @author guoxin
 * @date 2019/8/30
 */
public class ObservableTest {

	public static void main(String[] args) {
		// Observable observableThread = new ObservableThread<>(() -> {
		// try {
		// TimeUnit.SECONDS.sleep(10);
		// } catch (InterruptedException e) {
		// e.printStackTrace();
		// }
		// System.out.println("finished done.");
		// return null;
		// });
		//
		// observableThread.start();

		final TaskLifeCycle<String> lifeCycle = new TaskLifeCycle.EmptyLifeCycle<String>() {
			@Override
			public void onFinish(Thread thread, String result) {
				System.out.println("The result is " + result);
			}
		};

		// Observable observableThread = new ObservableThread<>(lifeCycle, () ->
		// {
		// try {
		// TimeUnit.SECONDS.sleep(10);
		// } catch (InterruptedException e) {
		// e.printStackTrace();
		// }
		// System.out.println("finished done.");
		// return "Hello Observer";
		// });
		Observable observableThread = new ObservableThread<>(lifeCycle, new Task<String>() {
			@Override
			public String call() {
				try {
					TimeUnit.SECONDS.sleep(10);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("finished done.");
				return "Hello Observer";
			}
		});

		observableThread.start();
	}
}
